#!/usr/bin/env python3
import pygame

import time
import math
# 模锟斤拷锟绞硷拷锟�
pygame.init()
pygame.joystick.init()

# 锟斤拷只锟斤拷锟斤拷锟斤拷一锟斤拷锟街憋拷锟斤拷锟剿达拷锟斤拷锟斤拷牟锟斤拷锟揭伙拷愣硷拷锟�0
joystick = pygame.joystick.Joystick(0)
# 锟街憋拷锟斤拷锟斤拷锟绞硷拷锟�
joystick.init()
xxx=0
yyy=0
theta=0
done = False
while not done:
        
    for event_ in pygame.event.get():
        
        if event_.type == pygame.JOYBUTTONDOWN or event_.type == pygame.JOYBUTTONUP:
           
            if joystick.get_button(3)==1:
               
               print("x")
           
            if joystick.get_button(4)==1: 
               
               print("y")
            if joystick.get_button(1)==1: 
            
                print("B")
            if joystick.get_button(0)==1: 
        
                print("A")
        elif event_.type == pygame.JOYAXISMOTION:
            xxx=joystick.get_axis(0)
            yyy=-joystick.get_axis(1)
            if 0.5>xxx and xxx>-0.5:
                if 0.5>yyy and yyy>-0.5:
                    yyy=0
                    xxx=0
            
            if xxx==0:
               theta=0
           
            if xxx!=0:
                if yyy==0:
                    theta=90 
                if yyy!=0:
                    theta=(math.atan(xxx/yyy))*57.3
            print(theta)
            
    theta=0
        

      
pygame.quit()
